package co.com.services.datosmaestros;

import javax.naming.NamingException;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import co.com.smart.maestro.infraestructure.dto.DatoMaestroDTO;
import co.com.smart.session.DelegateContextEJB;


@Path("/SmartDatosMaestrosServices")
public class DatosMaestrosServices {

	@GET
	@Path("/getAllDatosMaestros")	
	@Produces(MediaType.APPLICATION_JSON)
	public Response getDatosMaestros() throws NamingException {
		return Response.ok(DelegateContextEJB.getDatosMaestrosBeanLocal().consultarAllDatosMaestros())
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

	@POST
	@Path("/getDatosMaestrosId")	
	@Produces(MediaType.APPLICATION_JSON)
	public Response getDatosMaestrosId(DatoMaestroDTO json) throws NamingException {
		return Response.ok(DelegateContextEJB.getDatosMaestrosBeanLocal().consultarDatosMaestrosId(json))
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}
	
	@GET
	@Path("/getDatosMaestros")	
	@Produces(MediaType.APPLICATION_JSON)
	public Response getDatosMaestrosService() throws NamingException {
		return Response.ok(DelegateContextEJB.getDatosMaestrosBeanLocal().consultarDatosMaestros())
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

	@PUT
	@Path("/setDatosMaestros")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setDatosMaestros( DatoMaestroDTO json){ 
		return Response.ok(DelegateContextEJB.getDatosMaestrosBeanLocal().insertarDatosMaestros(json))
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
				.build();
	}

	@PUT
	@Path("/editDatosMaestros")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setEditDatosMaestros(DatoMaestroDTO json){ 
		return Response.ok(DelegateContextEJB.getDatosMaestrosBeanLocal().editDatosMaestros(json))
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

	@PUT
	@Path("/removeDatosMaestros")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setRemoveDatosMaestros(DatoMaestroDTO json){ 
		return Response.ok(DelegateContextEJB.getDatosMaestrosBeanLocal().removeDatosMaestros(json, true))
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

}
